import type { AdminRoleType, AuthorizedRoleFunctionsParams, RoleType } from "/@/api/aiot/role/models";
import type { ID } from "/@/api/models";
import { AiotSubApp } from "/@/base/data";

export enum Gender {
  female = "woman",
  male = "male",
  secrecy = "secrecy",
}

export interface UserItem {
  avatar?: ID;
  description?: string;
  companyEmail?: string;
  gender?: string;
  loginAccount?: string;
  nickName?: string;
  phone?: string;
  userName?: string;
  organizations?: string;
  userId?: string;
  userInfoId?: string;
  isActivated?: number;
  createOn?: string;
  roles?: string | string[];
  roleId?: string;
  roleIds?: string | string[];
  isLocked?: number;
  isSystem?: number;
  companyId?: string;
  region?: string | string[];
  location?: string;
  roleTypes?: RoleType | AdminRoleType;
  positionId?: string;
}

export interface UserSearchModel {
  isActivated?: number;
  organizationId?: string;
  searchText?: string;
}

export interface AddUserParams {
  companyId?: string | null;
  description?: string;
  companyEmail?: string;
  gender?: Gender;
  location?: string;
  nickName?: string;
  phone?: string;
  region?: string | string[];
  // roleIds?: string[];
  roleId?: string;
  userFolderPermissions?: AuthorizedRoleFunctionsParams["roleFolderPermissions"];
  userMenuPermissions?: AuthorizedRoleFunctionsParams["roleMenuPermissions"];
  userId?: string;
  positionId?: string;
}

export type UserState = "received" | "holiday" | "busy";
export const UserStateColor: Record<UserState, string> = {
  busy: "#FD8358",
  holiday: "#4B8BF4",
  received: "#2ECC74",
};

export interface UserDetail {
  userTenantInfoVo: {
    nickName: string;
    phone: string;
    genderName: string;
    companyEmail: string;
    companyName: string;
    userGroups: string;
    stateName: string;
    state: UserState | "";
    organizationName: string;
    tenantId: string;
    tenantRoles: { roleName: string; roleType: RoleType | AdminRoleType }[];
    tenantMaxRole: { roleName: string; roleType: RoleType | AdminRoleType | "" };
    location: string;
    workViewType: string;
  };
  userVo: {
    userId: string;
    userName: string;
    loginAccount: string;
  };
}

export enum GrantTypeEnum {
  CAPTCHA = "captcha",
  PASSWORD = "password",
}

export interface LoginParams {
  account: string;
  password: string;
  appType?: string;
  appCode?: AiotSubApp;
  code: string;
  grantType?: string;
  key?: string;
  rememberMe?: boolean;
  isRemPass?: boolean;
}

interface AuthInfo {
  account: string;
  name: string;
  token: string;
  userId: string | number;
}

export interface TenantInfo {
  tenantId: string;
  tenantNo: string;
  description: string;
  tenantName: string;
  isLock: boolean;
  endTimeValid: boolean;
  beginTimeValid: boolean;
  errorMsg: string;
  expirationDateFrom: string;
  expirationDateTo: string;
  companyShortName: string;
  companyFullName: string;
  tenantMaxRole: {
    roleName: string;
    roleType: RoleType | AdminRoleType | "";
  };
  nickName: string;
  logoImage: string;
}

export interface LoginResult {
  authInfo: AuthInfo;
  //所有可用的租户数据
  tenantInfos: TenantInfo[];
}
